/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;
import java.awt.Color;
import java.util.ArrayList;
//import javax.vecmath.*;

/**
 *
 * @author snowangelic
 */
public class DataSet {
    ArrayList<Action> actionList;
    ArrayList<Attribute> attributeList;
    ArrayList<Kmeans> kmeansList;

    DataSet(){
        actionList = new ArrayList<Action>();
        attributeList = new ArrayList<Attribute>();
        kmeansList=new ArrayList<Kmeans>();
    }

    // --- Accesseurs / Mutateurs / Informations pour les Actions ---

    /**
     *
     * @param attributes
     */
    public void addAction(ArrayList<AttributeValue> attributes){
        Action act=new Action(attributes);
        actionList.add(act);
    }

    public Action addAction(){
        Action act=new Action();
        actionList.add(act);
        return act;
    }

    /**
     *
     * @param index
     * @return
     */
    public Action getAction(int index){
        return actionList.get(index);
    }

    /**
     *
     * @return
     */
    public int getActionNbr(){
        return actionList.size();
    }

    public void setActionCoords(int index, float[] coords){
        getAction(index).setCoords(coords);
    }

    public float[]getActionCoords(int index){
        return getAction(index).getCoords();
    }

    public Color getActionColor(int index,Kmeans kmeans){
        return getAction(index).getColor(kmeans);
    }

    void setCluster(int index, Cluster cluster) {
        getAction(index).setCluster(cluster);
    }

    Cluster getCluster(int index,Kmeans kmeans){
        return getAction(index).getCluster(kmeans);
    }

    String getClusterName(int index,Kmeans kmeans){
        Cluster cluster=getCluster(index,kmeans);
        if(cluster==null) return "";
        else return cluster.getName();
    }

    // --- Accesseurs / Mutateurs / Informations pour les Attributs ---

    /**
     *
     * @param name
     * @param type
     */
    public void addAttribute(String name,AttributeType type){
            Attribute Attr=new Attribute(name,type);
            attributeList.add(Attr);
    }

    /**
     *
     * @return
     */
    public int getAttributeNbr(){
        return attributeList.size();
    }
    
    /**
     *
     * @param index
     * @return
     */
    public Attribute getAttribute(int index){
        return attributeList.get(index);
    }

    /**
     *
     * @param index
     * @return
     */
    public AttributeType getAttributeType(int index){
        return attributeList.get(index).getType();
    }

    /**
     *
     * @param attribute
     * @return
     */
    public AttributeType getAttributeType(Attribute attribute){
        int index=attributeList.indexOf(attribute);
        return attributeList.get(index).getType();
    }

    /**
     *
     * @param index
     * @return
     */
    public String getAttributeName(int index){
        return attributeList.get(index).getName();
    }

     // --- Accesseurs / Mutateurs / Informations pour les Valeurs des Attributs ---

    public void setValue(Action action,Attribute attribute,Object value){
        action.setValue(attribute,value);
    }
    /**
     *
     * @param actionIndex
     * @param attributeIndex
     * @return
     */
    public Object getValue(int actionIndex,int attributeIndex){
        Attribute attr = getAttribute(attributeIndex);
        Action act = getAction(actionIndex);
        return act.getValue(attr);
    }

    public Object getValue(int actionIndex,Attribute attribute){
        Action act = getAction(actionIndex);
        return act.getValue(attribute);
    }


     // --- Accesseurs / Mutateurs / Informations pour les Kmeans ---
    /**
     *
     * @param kmeans
     */

    public Kmeans addKmeans(String name,String distance){
        Distance dist=null;
         Kmeans kmeans=null;
        if(distance.equals("Euclidian")){
            dist=Distance.EUCLIDIAN;
            kmeans=new Kmeans(name,dist,this);
        }
        else { System.out.println("Mauvaise distance"); }
         kmeansList.add(kmeans);
        return kmeans;
    }
    public void addKmeans(Kmeans kmeans){
        kmeansList.add(kmeans);
    }

    public void addWeight(Kmeans kmeans,int attributeIndex,float attributeValue){
        kmeans.AddWeight(getAttribute(attributeIndex),attributeValue);
    }

    public void computeKmeans(Kmeans kmeans){
        kmeans.compute();
    }

    /**
     *
     * @return
     */
    public int getKmeansNbr() {
        return kmeansList.size();
    }

    /**
     *
     * @param index
     * @return
     */
    public Kmeans getKmeans(int index){
        return kmeansList.get(index);
    }

    /**
     *
     * @param index
     * @return
     */
    public String getKmeansName(int index){
        return getKmeans(index).getName();
    }

    public void addCluster(Kmeans kmeans,String name,Color color){
        kmeans.addCluster(name,color);
    }

    public void addCluster(Kmeans kmeans,String name,String color){
        kmeans.addCluster(name,color);
    }

    public void addWeight(Kmeans kmeans,Attribute attribute,float weightVal){
        kmeans.AddWeight(attribute, weightVal);
    }


}
